#include <iostream>
#include <memory>
#include "UdpServer.hpp"
#include "Route.hpp"
#include "InetAddr.hpp"

// ./udpserver port
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    uint16_t port = (uint16_t)std::stoi(argv[1]);

    // 1.创建路由对象
    Route route;

    // 2.创建服务端
    std::unique_ptr<UdpServer> udpserver = std::make_unique<UdpServer>(
        port, [&route](int sockfd, std::string data, InetAddr inetaddr)
        { route.MessageRoute(sockfd, data, inetaddr); });

    // 3.启动服务端
    udpserver->Start();

    return 0;
}